home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / simula / books / books.lha / kirkerud / histo1.sim < prev    next >
Text File  |  1993-08-16  |  1KB  |  41 lines

  1. ! The program constructed in the first part of 
  2. ! chapter 4 (section 4.7, fig. 4.3);
  3.  
  4. begin
  5.  
  6.   integer array count(5 : 200);
  7.   integer weight_group, least_weight_group,  greatest_weight_group,
  8.           asterisk_number, number_of_asterisks;
  9.   real    weight;
  10.  
  11. ! Read the measurements one by one:   ;
  12.      outtext(" Please type the weights. "); outimage;
  13.      outtext(" Remember to type -1 after the last one!");  outimage;
  14.    weight := inreal;
  15.    while weight ge 0 do
  16.    begin
  17.      weight_group := entier(weight);
  18.      count(weight_group) := count(weight_group) + 1;
  19.      weight := inreal;
  20.    end;
  21.  
  22. ! Find the least and greatest weight_groups containing weights:  ;
  23.    least_weight_group := 5;
  24.    while count(least_weight_group) = 0
  25.      do least_weight_group := least_weight_group + 1;
  26.    greatest_weight_group := 200;
  27.    while count(greatest_weight_group) = 0
  28.      do greatest_weight_group :=  greatest_weight_group - 1;
  29.  
  30. ! Write the histogram:   ;
  31.    outtext("Weight : Number of children"); outimage;
  32.    for weight_group := least_weight_group step 1  until greatest_weight_group do
  33.      begin
  34.        outint(weight_group, 6); outtext(" : ");
  35.        number_of_asterisks := count(weight_group);
  36.        for asterisk_number := 1 step 1  until number_of_asterisks do outchar('*');
  37.        outimage;
  38.      end of weight_group-repetition;
  39.  
  40. end;
  41.